package com.sgcc.sx.pmos.e_sx_order.presenter;

import com.sgcc.sx.pmos.common.base.BasePresenter;
import com.sgcc.sx.pmos.common.bean.BaseResponse;
import com.sgcc.sx.pmos.common.http.HttpInterConst;
import com.sgcc.sx.pmos.common.http.HttpRequestUtils;
import com.sgcc.sx.pmos.common.http.MvpNetCallback;
import com.sgcc.sx.pmos.common.utils.ListPageUtil;
import com.sgcc.sx.pmos.e_sx_order.bean.IndentBean;
import com.sgcc.sx.pmos.e_sx_order.bean.SupplementContractBean;
import com.sgcc.sx.pmos.e_sx_order.contract.ConfirmSupplementaryAgreementContract;
import com.sgcc.sx.pmos.e_sx_order.contract.ContractContract;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;

public class ConfirmSupplementaryAgreementPresenter extends BasePresenter<ConfirmSupplementaryAgreementContract.View> implements ConfirmSupplementaryAgreementContract.Presenter {


    @Override
    public void confirmSupplementContract(String flag, String relationId) {
        Map<String, Object> params = new HashMap<>();
        params.put("flag", flag);
        params.put("relationId", relationId);
        params.put("_t", System.currentTimeMillis());
        HttpRequestUtils.getInstance().request(params, HttpInterConst.ORDER_CONFIRMSUPPLEMENTCONTRACT, new MvpNetCallback<BaseResponse>(getView(), true) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                // 失败回调 判断界面是否销毁
                if (!isViewAttached()) {
                    return;
                }
            }

            @Override
            public void onResponse(BaseResponse response, int id) {
                super.onResponse(response, id);
                if (!isViewAttached()) {
                    return;
                }
                if (response != null) {
                    if (response.isSuccess()) {
                        getView().confirmSupplementContractSuccess();
                    }
                }
            }
        });
    }


    @Override
    public void getSupplementContractList(String relationId) {

        Map<String, Object> params = new HashMap<>();
        params.put("_t", System.currentTimeMillis());
        params.put("flag", "0");//1已确认,0未确认（查看补充协议选1，补充协议确认0）
        params.put("relationId", relationId);//订单ID
        HttpRequestUtils.getInstance().request(params, HttpInterConst.QUERY_SUPPLEMENT_CONTRACT,
                new MvpNetCallback<SupplementContractBean>(getView(), true) {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        super.onError(call, e, id);
                        // 失败回调 判断界面是否销毁
                        if (!isViewAttached()) {
                            return;
                        }
                    }

                    @Override
                    public void onResponse(SupplementContractBean response, int id) {
                        super.onResponse(response, id);
                        if (!isViewAttached()) {
                            return;
                        }
                        if (null != response && null != response.getData() && response.getData().size() > 0)
                            getView().getSupplementContractListSuccess(response.getData().get(0));
                        else {
                            getView().getSupplementContractListFailed();
                        }
                    }
                });


    }


}
